﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace WebRole1
{
    public partial class aPatients : System.Web.UI.Page
    {
        Service1 svc = new Service1();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //List<string> docList = svc.getDoctor();
            //foreach (string k in docList)
            //{
            //    ddlDoctor.Items.Add(k.ToString());
            //}

            //DateTime tnow = DateTime.Now;
            //ArrayList AlYear = new ArrayList();
            //int i;
            //for (i = 1920; i <= DateTime.Now.Year; i++)
            //    AlYear.Add(i);
            //ArrayList AlMonth = new ArrayList();
            //for (i = 1; i <= 12; i++)
            //    if (i < 10)
            //    {
            //        AlMonth.Add("0" + i);
            //    }
            //    else
            //    {
            //        AlMonth.Add(i);
            //    }

            //if (!this.IsPostBack)
            //{
            //    ddlYear.DataSource = AlYear;
            //    ddlYear.DataBind();
            //    ddlYear.SelectedValue = tnow.Year.ToString();
            //    ddlMonth.DataSource = AlMonth;
            //    ddlMonth.DataBind();
            //    ddlMonth.SelectedValue = tnow.Month.ToString();
            //    year = Int32.Parse(ddlYear.SelectedValue);
            //    month = Int32.Parse(ddlMonth.SelectedValue);
            //    BindDays(year, month);
            //    ddlDate.SelectedValue = tnow.Day.ToString();
            //}

            //ddlHospital.Items.Add("");
            //foreach (place p in svc.getPlace())
            //{
            //    ddlHospital.Items.Add(p.Name);
            //}
        }

        //#region bind date to ddl
        //int year;
        //int month;
        //private bool CheckLeap(int year)
        //{
        //    if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
        //        return true;
        //    else
        //        return false;
        //}

        //private void BindDays(int year, int month)
        //{
        //    int i;
        //    ArrayList AlDay = new ArrayList();

        //    switch (month)
        //    {
        //        case 1:
        //        case 3:
        //        case 5:
        //        case 7:
        //        case 8:
        //        case 10:
        //        case 12:
        //            for (i = 1; i <= 31; i++)
        //                if (i < 10)
        //                {
        //                    AlDay.Add("0" + i);
        //                }
        //                else
        //                {
        //                    AlDay.Add(i);
        //                }
        //            break;
        //        case 2:
        //            if (CheckLeap(year))
        //            {
        //                for (i = 1; i <= 29; i++)
        //                    if (i < 10)
        //                    {
        //                        AlDay.Add("0" + i);
        //                    }
        //                    else
        //                    {
        //                        AlDay.Add(i);
        //                    }
        //            }
        //            else
        //            {
        //                for (i = 1; i <= 28; i++)
        //                    if (i < 10)
        //                    {
        //                        AlDay.Add("0" + i);
        //                    }
        //                    else
        //                    {
        //                        AlDay.Add(i);
        //                    }
        //            }
        //            break;
        //        case 4:
        //        case 6:
        //        case 9:
        //        case 11:
        //            for (i = 1; i <= 30; i++)
        //                AlDay.Add(i);
        //            break;
        //    }
        //    ddlDate.DataSource = AlDay;
        //    ddlDate.DataBind();
        //}

        //protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    year = Int32.Parse(ddlYear.SelectedValue);
        //    month = Int32.Parse(ddlMonth.SelectedValue);
        //    BindDays(year, month);
        //}

        //protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    year = Int32.Parse(ddlYear.SelectedValue);
        //    month = Int32.Parse(ddlMonth.SelectedValue);
        //    BindDays(year, month);
        //}

        ////public static int CalculateAge(int year, int month, int day)
        ////{
        ////    DateTime now = DateTime.Today;
        ////    int years = now.Year - year;

        ////    if (now.Month < month || (now.Month == month && now.Day < day))
        ////        --years;

        ////    return years;
        ////}

        //#endregion

        protected void btnAddPatient_Click(object sender, EventArgs e)
        {
            //int age = CalculateAge(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlDate.SelectedValue));
            //string dob = ddlDate.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlYear.SelectedValue;
            ////string dob = ddlMonth.SelectedValue + "/" + ddlDate.SelectedValue + "/" + ddlYear.SelectedValue;
            //DateTime date = DateTime.ParseExact(dob, "dd/MM/yyyy", null);
            string dob = 20 + "/" + 03 + "/" + 1992;
            //string dob = ddlDate.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlYear.SelectedValue;
            //DateTime date = DateTime.ParseExact(dob, "dd/MM/yyyy", null);
            //DateTime date = DateTime.Parse(dob);
            //DateTime date = DateTime.ParseExact(Convert.ToDateTime("20/03/1992"),"dd/MM/yyyy",null);
            string x = tbxFirstName.Text.Replace(" ",string.Empty);
            string y = tbxLastName.Text.Replace(" ", string.Empty);
            int uid = svc.addNewAPatient(y, x, rblTitle.SelectedItem.ToString(), rblGender.SelectedItem.ToString(), ddlCountry.SelectedItem.ToString(), "", "", "", "", "", "", "", "Sunny", tbxNOKName.Text, tbxNOKAddress1.Text, tbxNOKAddress2.Text, tbxNOKPostalCode.Text, tbxNOKNum.Text);

            if (uid != -1)
            {
                if (ddlSeverityNeck.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "1", tbxProblemNeck.Text, tbxDescriptionNeck.Text, Convert.ToInt32(ddlSeverityNeck.SelectedValue.ToString()), tbxNotesNeck.Text);
                }
                if (ddlSeverityRightHip.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "10", tbxProblemRightHip.Text, tbxDescriptionRightHip.Text, Convert.ToInt32(ddlSeverityRightHip.SelectedValue.ToString()), tbxNotesRightHip.Text);
                }
                if (ddlSeverityLeftKnee.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "11", tbxProblemLeftKnee.Text, tbxDescriptionLeftKnee.Text, Convert.ToInt32(ddlSeverityLeftKnee.SelectedValue.ToString()), tbxNotesLeftKnee.Text);
                }
                if (ddlSeverityRightKnee.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "12", tbxProblemRightKnee.Text, tbxDescriptionRightKnee.Text, Convert.ToInt32(ddlSeverityRightKnee.SelectedValue.ToString()), tbxNotesRightKnee.Text);
                }
                if (ddlSeverityLeftFoot.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "13", tbxProblemLeftFoot.Text, tbxDescriptionLeftFoot.Text, Convert.ToInt32(ddlSeverityLeftFoot.SelectedValue.ToString()), tbxNotesLeftFoot.Text);
                }
                if (ddlSeverityRightFoot.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "14", tbxProblemRightFoot.Text, tbxDescriptionRightFoot.Text, Convert.ToInt32(ddlSeverityRightFoot.SelectedValue.ToString()), tbxNotesRightFoot.Text);
                }
                if (ddlSeverityLeftShoulder.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "2", tbxProblemLeftShoulder.Text, tbxDescriptionLeftShoulder.Text, Convert.ToInt32(ddlSeverityLeftShoulder.SelectedValue.ToString()), tbxNotesLeftShoulder.Text);
                }
                if (ddlSeverityRightShoulder.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "3", tbxProblemRightShoulder.Text, tbxDescriptionRightShoulder.Text, Convert.ToInt32(ddlSeverityRightShoulder.SelectedValue.ToString()), tbxNotesRightShoulder.Text);
                }
                if (ddlSeverityLeftElbow.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "4", tbxProblemLeftElbow.Text, tbxDescriptionLeftElbow.Text, Convert.ToInt32(ddlSeverityLeftElbow.SelectedValue.ToString()), tbxNotesLeftElbow.Text);
                }
                if (ddlSeverityRightElbow.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "5", tbxProblemRightElbow.Text, tbxDescriptionRightElbow.Text, Convert.ToInt32(ddlSeverityRightElbow.SelectedValue.ToString()), tbxNotesRightElbow.Text);
                }
                if (ddlSeverityLeftHand.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "6", tbxProblemLeftHand.Text, tbxDescriptionLeftHand.Text, Convert.ToInt32(ddlSeverityLeftHand.SelectedValue.ToString()), tbxNotesLeftHand.Text);
                }
                if (ddlSeverityRightHand.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "7", tbxProblemRightHand.Text, tbxDescriptionRightHand.Text, Convert.ToInt32(ddlSeverityRightHand.SelectedValue.ToString()), tbxNotesRightHand.Text);
                }
                if (ddlSeverityWaist.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "8", tbxProblemWaist.Text, tbxDescriptionWaist.Text, Convert.ToInt32(ddlSeverityWaist.SelectedValue.ToString()), tbxNotesWaist.Text);
                }
                if (ddlSeverityLeftHip.SelectedValue != "")
                {
                    bool problemCreated = svc.createProblem(uid, "9", tbxProblemLeftHip.Text, tbxDescriptionLeftHip.Text, Convert.ToInt32(ddlSeverityLeftHip.SelectedValue.ToString()), tbxNotesLeftHip.Text);
                }

                //ddlHospital.SelectedIndex = -1;
                //tbxAddress1.Text = "";
                //tbxAddress2.Text = "";
                //tbxContactNum.Text = "";
                //tbxContactNumHome.Text = "";
                //tbxContactNumWork.Text = "";
                //tbxDoctor.Text = "";
                //tbxEmail.Text = "";
                tbxFirstName.Text = "";
                tbxLastName.Text = "";
                tbxNOKName.Text = "";
                tbxNOKNum.Text = "";
                tbxNOKAddress1.Text = "";
                tbxNOKAddress2.Text = "";
                tbxNOKPostalCode.Text = "";
                //tbxPostalCode.Text = "";
                rblGender.SelectedIndex = -1;
                rblTitle.SelectedIndex = -1;
                ddlCountry.SelectedIndex = 0;
                //ddlDate.SelectedIndex = -1;
                //ddlMonth.SelectedIndex = -1;
                //ddlYear.SelectedIndex = -1;
                //ddlDoctor.SelectedIndex = -1;

                tbxProblemNeck.Text = ""; tbxDescriptionNeck.Text = ""; tbxNotesNeck.Text = ""; ddlSeverityNeck.SelectedIndex = -1;
                tbxProblemRightHip.Text = ""; tbxDescriptionRightHip.Text = ""; tbxNotesRightHip.Text = ""; ddlSeverityRightHip.SelectedIndex = -1;
                tbxProblemLeftKnee.Text = ""; tbxDescriptionLeftKnee.Text = ""; tbxNotesLeftKnee.Text = ""; ddlSeverityLeftKnee.SelectedIndex = -1;
                tbxProblemRightKnee.Text = ""; tbxDescriptionRightKnee.Text = ""; tbxNotesRightKnee.Text = ""; ddlSeverityRightKnee.SelectedIndex = -1;
                tbxProblemLeftFoot.Text = ""; tbxDescriptionLeftFoot.Text = ""; tbxNotesLeftFoot.Text = ""; ddlSeverityLeftFoot.SelectedIndex = -1;
                tbxProblemRightFoot.Text = ""; tbxDescriptionRightFoot.Text = ""; tbxNotesRightFoot.Text = ""; ddlSeverityRightFoot.SelectedIndex = -1;
                tbxProblemLeftShoulder.Text = ""; tbxDescriptionLeftShoulder.Text = ""; tbxNotesLeftShoulder.Text = ""; ddlSeverityLeftShoulder.SelectedIndex = -1;
                tbxProblemRightShoulder.Text = ""; tbxDescriptionRightShoulder.Text = ""; tbxNotesRightShoulder.Text = ""; ddlSeverityRightShoulder.SelectedIndex = -1;
                tbxProblemLeftElbow.Text = ""; tbxDescriptionLeftElbow.Text = ""; tbxNotesLeftElbow.Text = ""; ddlSeverityLeftElbow.SelectedIndex = -1;
                tbxProblemRightElbow.Text = ""; tbxDescriptionRightElbow.Text = ""; tbxNotesRightElbow.Text = ""; ddlSeverityRightElbow.SelectedIndex = -1;
                tbxProblemLeftHand.Text = ""; tbxDescriptionLeftHand.Text = ""; tbxNotesLeftHand.Text = ""; ddlSeverityLeftHand.SelectedIndex = -1;
                tbxProblemRightHand.Text = ""; tbxDescriptionRightHand.Text = ""; tbxNotesRightHand.Text = ""; ddlSeverityRightHand.SelectedIndex = -1;
                tbxProblemWaist.Text = ""; tbxDescriptionWaist.Text = ""; tbxNotesWaist.Text = ""; ddlSeverityWaist.SelectedIndex = -1;
                tbxProblemLeftHip.Text = ""; tbxDescriptionLeftHip.Text = ""; tbxNotesLeftHip.Text = ""; ddlSeverityLeftHip.SelectedIndex = -1;

                Response.Redirect("aConfirmation.aspx");
            }
            //if (svc.addNewPatient(tbxLastName.Text, tbxFirstName.Text, rblTitle.SelectedItem.ToString(), date, rblGender.SelectedItem.ToString(), ddlCountry.SelectedItem.ToString(), tbxAddress1.Text, tbxAddress2.Text, tbxPostalCode.Text, tbxContactNumHome.Text, tbxContactNumWork.Text, tbxContactNum.Text, tbxEmail.Text, tbxDoctor.Text, tbxNOKName.Text, null, tbxNOKNum.Text) == true)
            //{
            //    tbxAddress1.Text = "";
            //    tbxAddress2.Text = "";
            //    tbxContactNum.Text = "";
            //    tbxContactNumHome.Text = "";
            //    tbxContactNumWork.Text = "";
            //    tbxDoctor.Text = "";
            //    tbxEmail.Text = "";
            //    tbxFirstName.Text = "";
            //    tbxLastName.Text = "";
            //    tbxNOKName.Text = "";
            //    tbxNOKNum.Text = "";
            //    //tbxNOKRelationship.Text = "";
            //    tbxPostalCode.Text = "";
            //    rblGender.SelectedIndex = -1;
            //    rblTitle.SelectedIndex = -1;
            //    ddlCountry.SelectedIndex = -1;
            //    ddlDate.SelectedIndex = -1;
            //    ddlMonth.SelectedIndex = -1;
            //    ddlYear.SelectedIndex = -1;
            //    Response.Redirect("Confirmation.aspx");
            //}
        }
    }
}